<template>
<div class="login">
<el-form ref="loginForm" :rules="rules" :model="loginForm" >
  <div class="login-box">
    <div class="logo">经纪商后台管理系统</div>
    <el-form-item prop="account">
      <el-input v-model="loginForm.account" placeholder="请输入帐号"></el-input>
    </el-form-item>
    <el-form-item  prop="agentPassword">
      <el-input type="password" v-model="loginForm.agentPassword" placeholder="请输入密码"></el-input>
    </el-form-item>
    <div>
      <el-button type="primary" style="width:100%" :disabled="isDisabled" @click="goLogin('loginForm')">登录</el-button>
    </div>
  </div>
</el-form>
  </div>
</template>

<style scoped>
.login{
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: url("/static/images/banner1-1.jpg") #409EFF;
  background-size: cover;
}
.logo{
  font-size: 20px;
  text-align: center;
  color: #fff;
  padding-bottom: 20px;
}
.login-box{
  width: 300px;
  background: rgba(0,0,0,0.4);
  border-radius: 5px;
  padding: 30px;
}
</style>

<script>
  import service from '@/service/index'
  import { setCookie,delCookie,getCookie } from '@/base/utils'
export default {
  data() {
    return {
      isDisabled:false,
      loginForm: {
        account: "",  //admin_AG000  ag001
        agentPassword: ""   //000000
      },
      rules:{
        account:[
          { required: true, message: '请输入帐号', trigger: 'blur' }
        ],
        agentPassword:[
          { required: true, message: '请输入密码', trigger: 'blur' },
        ],
      },
      navListNoShop:[{
        indexName:'home',
        className:'icon-zhuye',
        title:'主页管理',
      },{
        indexName:'pushed',
        className:'icon-tuisong',
        title:'推送管理',
      },{
        indexName:'reward',
        className:'icon-dashang',
        title:'打赏列表',
      },{
        indexName:'lives',
        className:'icon-shipin',
        title:'直播管理',
      }],
      navListNoLives:[{
        indexName:'home',
        className:'icon-zhuye',
        title:'主页管理',
      },{
        indexName:'pushed',
        className:'icon-tuisong',
        title:'推送管理',
      },{
        indexName:'shopping',
        className:'icon-yly_jifenshangcheng',
        title:'积分商城管理',
      },{
        indexName:'apply',
        className:'icon-daishenhe',
        title:'积分消费审批',
      },{
        indexName:'advert',
        className:'icon-tupian',
        title:'广告位管理',
      }],
      navListAll:[{
        indexName:'home',
        className:'icon-zhuye',
        title:'主页管理',
      },{
        indexName:'pushed',
        className:'icon-tuisong',
        title:'推送管理',
      },{
        indexName:'shopping',
        className:'icon-yly_jifenshangcheng',
        title:'积分商城管理',
      },{
        indexName:'apply',
        className:'icon-daishenhe',
        title:'积分消费审批',
      },{
        indexName:'reward',
        className:'icon-dashang',
        title:'打赏列表',
      },{
        indexName:'advert',
        className:'icon-tupian',
        title:'广告位管理',
      },{
        indexName:'lives',
        className:'icon-shipin',
        title:'直播管理',
      }],
      navListNoItem:[{
        indexName:'home',
        className:'icon-zhuye',
        title:'主页管理',
      },{
        indexName:'pushed',
        className:'icon-tuisong',
        title:'推送管理',
      }]
    };
  },
  mounted(){
    this.isCookie();
  },
  methods: {
    isCookie(){
      delCookie("userInfo");
      delCookie("agentList");
      delCookie("navList");
      delCookie("baseInfo");
      delCookie("baseInfo");
    },
    goLogin(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let params = {
            account:this.loginForm.account,
            password:this.loginForm.agentPassword
          }
          this.isDisabled = true;
          service.haiBeiServerLogin(params).then(res => {
            if(res.success) {
              this.getNavItems();
              setTimeout( () => {
                setCookie("baseInfo",res.result);
                this.$router.push({ name: 'main'});
                this.isDisabled = false;
              }, 2000 );
            }else{
              this.$message({type:'error', message:res.msg});
              this.isDisabled = false;
              return;
            }
          });
        } else {
          return false;
        }
      });

    },
    getNavItems(){
      service.haiBeiServerQueryAgentInfo({}).then(res => {
        if (res.success) {
          if(res.result.shopping_status=='0'){
            setCookie("navList",this.navListNoShop);
          }
          if(res.result.broadcast_status=='0'){
            setCookie("navList",this.navListNoLives);
          }
          if(res.result.shopping_status=='0'&&res.result.broadcast_status=='0'){
            setCookie("navList",this.navListNoItem);
          }
          if(res.result.shopping_status=='1'&&res.result.broadcast_status=='1'){
            setCookie("navList",this.navListAll);
          }
        }else{
          this.$message({type:'error', message:res.msg});
          return;
        }
      });
    }
  }
};
</script>
